<!-- 区域渐变折线图（智慧运营>>人员管控、车辆管控...） -->
<template>
  <div class="gradient-line-chart">
    <base-echarts :options="chartOptions" />
  </div>
</template>

<script>
import * as echarts from "echarts";
import BaseEcharts from "./BaseEcharts.vue";
import { TOOLTIP_COMMON } from "@/assets/js/constant";
export default {
  name: "GradientLineChart",
  components: {
    BaseEcharts,
  },
  props: {
    // 折线图特有配置数据
    chartExtraData: {
      type: Object,
      default: () => {},
    },
  },
  computed: {
    chartOptions() {
      const { grid, xAxisData, yAxisName, lineStyleColor, areaStyleColor, seriesData } = this.chartExtraData;
      return {
        tooltip: {
          trigger: "axis",
          ...TOOLTIP_COMMON,
        },
        grid: {
          ...grid,
          containLabel: true,
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          axisLine: {
            lineStyle: {
              color: "#384b61",
            },
          },
          axisLabel: {
            color: "#b8dcf8",
            fontSize: 14,
          },
          axisTick: {
            show: false,
          },
          splitLine: {
            show: true,
            lineStyle: {
              color: "#3A4E68",
              type: "dashed",
            },
          },
          data: xAxisData,
        },
        yAxis: {
          type: "value",
          name: yAxisName,
          nameTextStyle: {
            color: "#A1A6AA",
            fontSize: 14,
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            lineStyle: {
              color: "#3A4E68",
              type: "dashed",
            },
          },
          axisLabel: {
            margin: 10,
            textStyle: {
              fontSize: 14,
              color: "#A1A6AA",
            },
          },
          splitLine: {
            lineStyle: {
              color: "#3A4E68",
              type: "dashed",
            },
          },
        },
        series: [
          {
            name: yAxisName,
            type: "line",
            symbol: "circle",
            symbolSize: 5,
            showSymbol: false,
            lineStyle: {
              normal: {
                width: 2,
                color: new echarts.graphic.LinearGradient(1, 0, 0, 0, [
                  {
                    offset: 0,
                    color: lineStyleColor,
                  },
                  {
                    offset: 0.5,
                    color: "#fff",
                  },
                  {
                    offset: 1,
                    color: lineStyleColor,
                  },
                ]),
              },
            },
            areaStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(
                  0,
                  0,
                  0,
                  1,
                  [
                    {
                      offset: 0,
                      color: areaStyleColor,
                    },
                    {
                      offset: 1,
                      color: "#000",
                    },
                  ],
                  false,
                ),
              },
            },
            data: seriesData,
          },
        ],
      };
    },
  },
};
</script>
<style scoped lang="scss">
.gradient-line-chart {
  height: 100%;
}
</style>
